package com.example.aop.aop;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class RecordTime {
    @Around("execution(* com.example.aop.test.*.*(..))")
    public Object time(ProceedingJoinPoint pjp) throws Throwable {
        //记录开始时间
        long beginTime=System.currentTimeMillis();
        //执行指定方法
        Object proceed = pjp.proceed();
        //记录结束时间
        long endTime=System.currentTimeMillis();
        log.info(pjp.getSignature()+"方法耗时{}:ms",endTime-beginTime);
        return proceed;
    }


}
